/**
 * Created by root on 2017/1/12.
 */
import React, { Component, PropTypes } from 'react';
import { Utility } from 'components';

export default class PeopleTaskList extends Component {
  static propTypes = {
    PeopleTaskList: PropTypes.array,
    onItemClick: PropTypes.func,
    IsShowLoadingComplete: PropTypes.bool,
    peopleTaskList: PropTypes.array,
    aboutUrl: PropTypes.func,
    aboutNextPage: PropTypes.func
  };
  constructor(props) {
    super(props);
    this.state = {
    };
  }
  __handleClick(obj) {
    const { aboutNextPage } = this.props;
    aboutNextPage(obj);
  }
  __handleOnClick(url) {
    const { aboutUrl } = this.props;
    aboutUrl(url);
  }
  __getStatelist(styles, dataeArr) {
    if (!dataeArr || !dataeArr.extTaskUserHistories) {
      return null;
    }
    const _items = dataeArr.extTaskUserHistories.map((obj, index) => {
      return (
        <div className={styles.stateline} key={index}>
          <div className={styles.time}>{obj.createTime ? Utility.$convertToDateByTimestamp(obj.createTime, 'MM-dd HH:mm') : ''}</div>
          <div className={styles.state}>{this.__getState(obj.status)}</div>
        </div>
      );
    });
    return _items;
  }
  __getState(status) {
    let statusStr = '';
    if (!status) {
      return '';
    }
    switch (status) {
      case Utility.constItem.Task.Task_START:    // 未处理
        statusStr = '未处理';
        break;
      case Utility.constItem.Task.Task_RECEIVED:  // 收到
        statusStr = '已收到';
        break;
      case Utility.constItem.Task.Task_FINISHED:  // 完成
        statusStr = '已完成';
        break;
      case Utility.constItem.Task.Task_REFUSE:   // 拒绝
        statusStr = '已拒绝';
        break;
      case Utility.constItem.Task.Task_OVER:     // 结束
        statusStr = '已结束';
        break;
      default:
        break;
    }
    return statusStr;
  }
  __GetArticalList(styles) {
    let dataeArr = [];
    const { peopleTaskList } = this.props;
    if (peopleTaskList) {
      dataeArr = peopleTaskList;
    }
    const _items = dataeArr.map((obj, index) => {
      return (
        <div className={styles.peopleContent} key={index}>
          <div className={styles.people}>
            <div className={styles.icon} />
            <div className={styles.name}>{obj.taskUserName ? obj.taskUserName : ''}</div>
            <div className={obj.status === Utility.constItem.Task.Task_REFUSE ? styles.state2 : styles.state}>{this.__getState(obj.status)}</div>
          </div>
        </div>
      );
    });
    return _items;
  }
  render() {
    const styles = require('./scss/PeopleTaskList.scss');
    let { IsShowLoadingComplete } = this.props;
    let { peopleTaskList } = this.props;
    if (!peopleTaskList) {
      peopleTaskList = [];
    }
    if (peopleTaskList.length === 0) {
      IsShowLoadingComplete = false;
    }
    return (
      <div className={styles.content}>
        {this.__GetArticalList(styles)}
        {
          IsShowLoadingComplete ? <div className={styles.complateInfo}>内容全部加载完成</div> : ''
        }
      </div>
    );
  }
}
